# -*- coding: utf-8 -*-
import scrapy
from scrapy.http import Request
import json
from cee_score.items import School


class CeeSpider(scrapy.Spider):
    name = "cee"
    download_delay = 0.1
    basic_url = 'http://data.api.gkcx.eol.cn/soudaxue/querySpecialtyScore.html?messtype=json&url_sign=querySpecialtyScore&provinceforschool=%E8%BE%BD%E5%AE%81&size=50&page='
    allowed_domains = ["*"]
    start_urls = (
    )

    def start_requests(self):
        for i in xrange(3001,3430):
            yield scrapy.Request(self.basic_url + str(i), callback=self.parse)


    def parse(self, response):
        schooldata = json.loads(response.body_as_unicode())
        print "total record is:" + schooldata['totalRecord']['num']
        schools = schooldata['school']
        for school in schools:
            # a_school = School()
            # a_school['schoolname'] = school['schoolname']
            # a_school['specialtyname'] = school['specialtyname']
            # a_school['localprovince'] = school['localprovince']
            # a_school['studenttype'] = school['studenttype']
            # a_school['year'] = school['year']
            # a_school['batch'] = school['batch']
            # a_school['var_score'] = school['var_score']
            # a_school['max'] = school['max']
            # a_school['min'] = school['min']
            yield  school

